home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-09-06 | 7.7 KB | 393 lines | [TEXT/CWIE] |
- // EditText.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "DDocData.h"
- #include "EverythingEngine.h"
- #include "EverythingDoc.h"
-
- #include "EditText.h"
-
-
- //----------
- void EditText::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- EditText* winObj = new EditText;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- EditText::EditText ()
- {
- mData = nil;
- }
-
- //----------
- EditText::~EditText ()
- {
- }
-
- //----------
- EverythingEngine* EditText::GetEngine ()
- {
- return (EverythingEngine*) mDoc->mEngine;
- }
-
- //----------
- void EditText::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_EditText, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((EverythingDoc*)mDoc)->mEditTextPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_EditText);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mSmallHandle = ::GetNewControl (CNTL_Small, window);
- SetWindowItemFont (mSmallHandle, wftb, 1);
-
- mLargeHandle = ::GetNewControl (CNTL_Large, window);
- SetWindowItemFont (mLargeHandle, wftb, 2);
-
- mX12345Handle = ::GetNewControl (CNTL_X12345, window);
- SetWindowItemFont (mX12345Handle, wftb, 3);
-
- mX12345e6Handle = ::GetNewControl (CNTL_X12345e6, window);
- SetWindowItemFont (mX12345e6Handle, wftb, 4);
-
- mPasswordHandle = ::GetNewControl (CNTL_Password, window);
- SetWindowItemFont (mPasswordHandle, wftb, 5);
-
- mDateHandle = ::GetNewControl (CNTL_Date, window);
- SetWindowItemFont (mDateHandle, wftb, 6);
-
- mTimeHandle = ::GetNewControl (CNTL_Time, window);
- SetWindowItemFont (mTimeHandle, wftb, 7);
-
- mStyledHandle = ::GetNewControl (CNTL_Styled, window);
- SetWindowItemFont (mStyledHandle, wftb, 8);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void EditText::Close ()
- {
- mData->RemoveResponder (this);
-
- ((EverythingDoc*)mDoc)->mEditTextPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void EditText::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- SetControlText (mSmallHandle, mData->GetSmall ());
- SetControlText (mLargeHandle, mData->GetLarge ());
- SetControlTextValue (mX12345Handle, mData->GetX12345 ());
- SetControlTextFloat (mX12345e6Handle, mData->GetX12345e6 ());
- SetControlText (mPasswordHandle, mData->GetPassword ());
- SetClockDateTime (mDateHandle, mData->GetDate ());
- SetClockDateTime (mTimeHandle, mData->GetTime ());
- SetControlText (mStyledHandle, mData->GetStyled ());
- }
-
- //----------
- void EditText::DataChanged (
- long inDataID)
- {
- if (inDataID == idSmall) {
- SetControlText (mSmallHandle, mData->GetSmall ());
- }
- if (inDataID == idLarge) {
- SetControlText (mLargeHandle, mData->GetLarge ());
- }
- if (inDataID == idX12345) {
- SetControlTextValue (mX12345Handle, mData->GetX12345 ());
- }
- if (inDataID == idX12345e6) {
- SetControlTextFloat (mX12345e6Handle, mData->GetX12345e6 ());
- }
- if (inDataID == idPassword) {
- SetControlText (mPasswordHandle, mData->GetPassword ());
- }
- if (inDataID == idDate) {
- SetClockDateTime (mDateHandle, mData->GetDate ());
- }
- if (inDataID == idTime) {
- SetClockDateTime (mTimeHandle, mData->GetTime ());
- }
- if (inDataID == idStyled) {
- SetControlText (mStyledHandle, mData->GetStyled ());
- }
- }
-
- //----------
- void EditText::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mSmallHandle) {
- HandleEditClick (mSmallHandle, where);
- }
- if (whichControl == mLargeHandle) {
- HandleEditClick (mLargeHandle, where);
- }
- if (whichControl == mX12345Handle) {
- HandleEditClick (mX12345Handle, where);
- }
- if (whichControl == mX12345e6Handle) {
- HandleEditClick (mX12345e6Handle, where);
- }
- if (whichControl == mPasswordHandle) {
- HandleEditClick (mPasswordHandle, where);
- }
- if (whichControl == mDateHandle) {
- HandleEditClick (mDateHandle, where);
- }
- if (whichControl == mTimeHandle) {
- HandleEditClick (mTimeHandle, where);
- }
- if (whichControl == mStyledHandle) {
- HandleEditClick (mStyledHandle, where);
- }
- }
-
- //----------
- void EditText::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void EditText::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- } else if (focus == mSmallHandle) {
- mData->SetSmall (GetEditTextChars (mSmallHandle));
- } else if (focus == mLargeHandle) {
- mData->SetLarge (GetEditTextChars (mLargeHandle));
- } else if (focus == mX12345Handle) {
- mData->SetX12345 (GetControlTextValue (mX12345Handle));
- } else if (focus == mX12345e6Handle) {
- mData->SetX12345e6 (GetControlTextFloat (mX12345e6Handle));
- } else if (focus == mPasswordHandle) {
- mData->SetPassword (GetEditTextChars (mPasswordHandle));
- } else if (focus == mDateHandle) {
- mData->SetDate (GetClockDateTime (mDateHandle));
- } else if (focus == mTimeHandle) {
- mData->SetTime (GetClockDateTime (mTimeHandle));
- } else if (focus == mStyledHandle) {
- mData->SetStyled (GetEditTextChars (mStyledHandle));
- }
- }
-
- //----------
- void EditText::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void EditText::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void EditText::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void EditText::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void EditText::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void EditText::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void EditText::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void EditText::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void EditText::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void EditText::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- Boolean EditText::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-